﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using QMERP.Domain.Entities;

namespace QMERP.Infrastructure.EFCore.Mappings
{
    public class CustomerMapping : IEntityTypeConfiguration<Customer>
    {
        public void Configure(EntityTypeBuilder<Customer> builder)
        {
            builder.HasQueryFilter(x => x.IsEnable);

            builder.Property(x => x.Level).IsRequired(false);
            builder.Property(x => x.PId).IsRequired(false);
            builder.Property(x => x.Code).HasMaxLength(10);
            builder.Property(x => x.Name).HasMaxLength(50);
            builder.Property(x => x.ShortName).IsRequired(false).HasMaxLength(20);
            builder.Property(x => x.Address).IsRequired(false).HasMaxLength(800);
            builder.Property(x => x.BillingAddress).IsRequired(false).HasMaxLength(800);

            builder.Property(x => x.Telephone).IsRequired(false).HasMaxLength(50);
            builder.Property(x => x.Fax).IsRequired(false).HasMaxLength(50); 
            builder.Property(x => x.Email).IsRequired(false).HasMaxLength(50);

            builder.Property(x => x.AreaCode).IsRequired(false).HasMaxLength(20);
            builder.Property(x => x.TradeCode).IsRequired(false).HasMaxLength(10);
            
            builder.Property(x => x.PostCode).IsRequired(false).HasMaxLength(20);

            builder.Property(x => x.Bank).IsRequired(false).HasMaxLength(10);
            builder.Property(x => x.BankAccount).IsRequired(false).HasMaxLength(20);
            builder.Property(x => x.TaxCode).IsRequired(false).HasMaxLength(10);
            builder.Property(x => x.TaxRate).IsRequired(false).HasPrecision(18, 2);
            builder.Property(x => x.PayCode).IsRequired(false).HasMaxLength(20);
            builder.Property(x => x.CurrencyCode).IsRequired(false).HasMaxLength(10);
            builder.Property(x => x.Signer).IsRequired(false).HasMaxLength(50);
            builder.Property(x => x.BarCode).IsRequired(false).HasMaxLength(20);
            builder.Property(x => x.ContactType).IsRequired(false).HasMaxLength(10);
            builder.Property(x => x.CreditGrade).IsRequired(false).HasMaxLength(10);
            builder.Property(x => x.CreditMoney).IsRequired(false).HasPrecision(18, 2);
            builder.Property(x => x.SpecialDiscount).IsRequired(false);
            builder.Property(x => x.ReferenceCode).IsRequired(false).HasMaxLength(20);
            builder.Property(x => x.ConvertCusCode).IsRequired(false).HasMaxLength(20);
            builder.Property(x => x.TransferWayCode).IsRequired(false).HasMaxLength(10);
            builder.Property(x => x.FreightTaxCode).IsRequired(false).HasMaxLength(20);
            builder.Property(x => x.IsShowPrice);
            builder.Property(x => x.AccountCode).IsRequired(false).HasMaxLength(20);

            builder.Property(x => x.OrganizationId);

            builder.HasIndex(x => x.Id);
            builder.HasIndex(x => x.Code);
            builder.HasIndex(x => x.Name);
            builder.HasIndex(x => x.OrganizationId);
            builder.HasIndex(x => x.CreatedOn).IsDescending();
        }
    }
}
